package com.mbc.mapper;


import com.mbc.pojo.MbcLikeClassificationTable;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.springframework.web.bind.annotation.RequestParam;

import java.time.LocalDateTime;
import java.util.List;

/**
 * <p>
 * 点赞分类表 Mapper 接口
 * </p>
 *
 * @author suimeng
 * @since 2024-04-10
 */
@Mapper
public interface LikeClassificationTableMapper {

    /**
     * 分页分类查询点赞列表
     *
     * @param userId 用户 ID
     * @param code   法典
     * @param offset 抵消
     * @param limit  限制
     * @return {@link List}<{@link MbcLikeClassificationTable}>
     */
    @Select("select * from mbc_like_classification_table where user_id = #{userId} and code = #{code} order by " +
            "like_time desc limit #{offset},#{limit}")
    List<MbcLikeClassificationTable> getLikeCodeList(Integer userId, Integer code);

    /**
     * 分页获取点赞列表
     *
     * @param userId 用户 ID
     * @param offset 抵消
     * @param limit  限制
     * @return {@link List}<{@link MbcLikeClassificationTable}>
     */
    @Select("select * from mbc_like_classification_table where user_id = #{userId} order by like_time desc")
    List<MbcLikeClassificationTable> getLikeList(Integer userId);

    /**
     * 新增点赞
     *
     * @param userId  用户 ID
     * @param likeUrl 喜欢 url
     * @param code    法典
     * @param now     现在
     * @return int
     */
    @Insert("insert into mbc_like_classification_table(user_id, code, like_url, like_time)" +
            "values (#{userId},#{code},#{likeUrl},#{now})")
    int insertLike(Integer userId, String likeUrl, Integer code, LocalDateTime now);

    /**
     * 取消点赞
     *
     * @param userId  用户 ID
     * @param likeUrl 喜欢 url
     * @return int
     */
    @Delete("delete from mbc_like_classification_table where user_id = #{userId} and like_url = #{likeUrl}")
    int deleteLike(Integer userId, String likeUrl);
}
